package top.dingyingying.demo.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import top.dingyingying.demo.base.PageBean;
import top.dingyingying.demo.base.R;
import top.dingyingying.demo.entity.TbCpu;
import top.dingyingying.demo.service.TbCpuService;
import top.dingyingying.demo.vo.PageVo;

import java.util.List;

@RestController
@RequestMapping("/cpu")
@RequiredArgsConstructor
public class TbCpuController {
    private final TbCpuService tbCpuService;

    @PostMapping("")
    public R<String> insert(@RequestBody TbCpu tbCpu) {
        return tbCpuService.insert(tbCpu);
    }

    @GetMapping("/{id}")
    public R<TbCpu> queryById(@PathVariable Integer id) {
        return tbCpuService.queryById(id);
    }

    @GetMapping("/{pn}/{ps}")
    public R<PageVo<TbCpu>> queryPage(@PathVariable("pn")Long pageNumber,@PathVariable("ps")Long pageSize,TbCpu tbCpu){
       return tbCpuService.queryPage(PageBean.instance(pageNumber,pageSize), tbCpu);
    }
    @PutMapping("")
    public R<String> update(@RequestBody TbCpu tbCpu){
        return tbCpuService.update(tbCpu);
    }
    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable("id") Integer id){return tbCpuService.delete(id);}

}
